/**
 * @param {string[]} patterns
 * @param {string} word
 * @return {number}
 */
/* var numOfStrings = function (patterns, word) {
  let n = patterns.length;
  let sum = 0;
  for (let i = 0; i < n; i++) {
    if (word.indexOf(patterns[i]) !== -1) sum++;
  }
  return sum;
};*/

var numOfStrings = function (patterns, word) {
  let n = patterns.length;
  let sum = 0;
  for (let i = 0; i < n; i++) {
    // 子串比父串还长，直接跳过
    if (patterns[i].length > word.length) continue;
    // 正则匹配
    if(RegExp(patterns[i]).test(word)) sum++;
  }
  return sum;
};

let patterns = ["a", "abc", "bc", "d"],
  word = "abc";
let demo = numOfStrings(patterns, word);
console.log(demo);
